<template>
 <model-page>
	<Search :searchResult="serchText">
		<view  @click="cancelSearch">
			取消
		</view>
	</Search>
 <view class="em">
 	
 </view>
	<BuildIng @confirm="confirm" :formData="postData"/>
		<view class="tables">
			<Table
			:headList="headList" 
			:tableData="tableData"
			:stateList="stateList"
			 :paging="false"
			></Table>
		</view>

 </model-page>
</template>

<script setup>
	import {reactive, ref} from 'vue'
	import Search from '@/component/Search.vue'
	import Table from '../../../component/Table.vue';
	import BuildIng from '@/component/Builing.vue'
	import {onLoad} from '@dcloudio/uni-app'
	import {listVisitForGuard} from '@/api/index.js'
	const stateList  = [
		{
			id:"3",
			label:"详情",
			color:"#2778FF",
			path:"/packageVisite/pages/mwVisiteInfo/mwVisiteInfo"
		}
	]
	const headList = ref([
		{
			title:"所属楼栋",
			props:"buildingName",
			width:"18%"
		},
		{
			title:"所属楼层",
			props:"floorName",
			width:"18%"
		},
		{
			title:"房间号",
			props:"roomNumber",
			width:"14%"
		},
		{
			title:"床号",
			props:"bedNumber",
			width:"18%"
		},
		{
			title:"老人名",
			props:"elderName",
			width:"12%"
		},
		{
			title:"操作",
			props:"visiteleaveStatus",
			width:"10%"
		},
	])
	const tableData = ref([])
	const serchText = ref("")
	const cancelSearch = ()=>{
		serchText.value = ""
		delete postData.value.elderId
		resetGetList()
	}
	const postData = ref({
		buildId:"",
		floorId:"",
		roomId:""
	})
	//根据楼栋查询老人列表
	const confirm = async(e)=>{
        postData.value.buildId = e.buildId
		postData.value.floorId = e.floorId
		postData.value.roomId = e.roomId
		resetGetList()
	}
	// 查询列表
	const getFilterList = async()=>{
		const {code,data:res} = await listVisitForGuard(postData.value)
		if(code === 200){
			if(res.length > 0){
				tableData.value = res.map(val=>{
					return Object.assign(val,{visiteleaveStatus:"3"})
				})
			}else{
				tableData.value = []
			}
		}
	}
	const resetGetList = ()=>{
		const {buildId,floorId,roomId,elderId} = postData.value
		if(buildId || floorId || roomId){
			getFilterList()
		}else if(elderId){
			
		}
		else{
				tableData.value = []
		}
	}
	onLoad(()=>{
		uni.$on("undateElderId",(option)=>{
			const {type,searchResult} = option
			serchText.value = searchResult || ""
			postData.value.elderId = type
			postData.value.buildId = ""
			postData.value.floorId = ""
			postData.value.roomId = ""
			getFilterList()
		})
	})
</script>

<style lang="less" scoped>
	.scan{
		width: 40rpx;
		height: 40rpx;
	}
	.tables{
		margin-top: 25rpx;
	}
.em{
	height: 35rpx;
}
</style>